package com.oyb.servlet;

import com.oyb.entity.Classes;
import com.oyb.service.ClassServies;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/classesinsert")
public class ClassesinsertServlet extends HttpServlet {
    private ClassServies classServies = new ClassServies();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Classes classes = new Classes();
        String class_name = req.getParameter("class_name");
//        classes.setId(null);
        classes.setClass_name(class_name);
        classes.setClass_count(0);
        int result = classServies.insertclass(classes);
        if(result>0){
            //新增成功
            resp.sendRedirect("classesquerypage");
        }else{
            //失败
            resp.sendRedirect("insertclass.jsp?status=1");
        }
    }
}
